﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FWMS
{
    public partial class Form_chanpingguanlicailiaochoose : Form
    {
        public Form_chanpingguanlicailiaochoose()
        {
            InitializeComponent();
        }
        public string yuancailiaostr;
        public string fuliaostr;
        public string tiaoweiliaostr;
        public int yuancailiaorows;
        public int tiaoweiliaorows;
        public int fuliaorows;
        public int fornum;
        public object[,] yuancailiaoSelectresult;
        public object[,] tiaoweiliaoSelectresult;
        public object[,] fuliaoSelectresult;
        private void Form_chanpingguanlicailiaochoose_Load(object sender, EventArgs e)
        {
            //材料选择初使化
            this.ControlBox = false;
            COMMAND.CommandBean.formflag = false;
            Service.CailiaoChooseService cailiaochooseservice = new FWMS.Service.CailiaoChooseService();
            Bean.CailiaoChooseBean bean = new FWMS.Bean.CailiaoChooseBean();
            bean = cailiaochooseservice.cailiaoChooseServiceSelectContation();
            yuancailiaorows = bean.Yuancailiaorows;
            tiaoweiliaorows = bean.Tiaoweiliaorows;
            fuliaorows = bean.Fuliaorows;
            yuancailiaoSelectresult = bean.YuancailiaoSelectresult;
            tiaoweiliaoSelectresult = bean.TiaoweiliaoSelectresult;
            fuliaoSelectresult = bean.FuliaoSelectresult;
            datagridviewadddata();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool abc = false;
            /*
            if (this.cailiaochoose.Rows[0].Cells[0].Value != null)
            {
                abc = (bool)this.cailiaochoose.Rows[0].Cells[0].Value;
            }
            if (this.cailiaochoose.Rows[0].Cells[2].Value != null)
            {
                abc = (bool)this.cailiaochoose.Rows[0].Cells[2].Value;
            }  */
            // this.Close();
            for (int j = 0; j < fornum; j++)
            {
                if (this.cailiaochoose.Rows[j].Cells[0].Value != null)
                {
                    if ((bool)this.cailiaochoose.Rows[j].Cells[0].Value)
                    {
                        yuancailiaostr = yuancailiaostr + this.cailiaochoose.Rows[j].Cells[1].Value + ",";
                    }
                }

                if (this.cailiaochoose.Rows[j].Cells[2].Value != null)
                {
                    if ((bool)this.cailiaochoose.Rows[j].Cells[2].Value)
                    {
                        tiaoweiliaostr = tiaoweiliaostr + this.cailiaochoose.Rows[j].Cells[3].Value + ",";
                    }
                }

                if (this.cailiaochoose.Rows[j].Cells[4].Value != null)
                {
                    if ((bool)this.cailiaochoose.Rows[j].Cells[4].Value)
                    {
                        fuliaostr = fuliaostr + this.cailiaochoose.Rows[j].Cells[5].Value + ",";
                    }
                }
            }
            if (yuancailiaostr!=null)
            {
                COMMAND.CommandBean.yuancailiaochoose = yuancailiaostr.Substring(0, yuancailiaostr.Length - 1);
            }
            if (tiaoweiliaostr != null)
            {
                COMMAND.CommandBean.tiaoweiliaochoose = tiaoweiliaostr.Substring(0, tiaoweiliaostr.Length - 1);
            }
            if (fuliaostr != null)
            {
                COMMAND.CommandBean.fuliaochoose = fuliaostr.Substring(0, fuliaostr.Length - 1);
            }
            yuancailiaostr = "";
            tiaoweiliaostr = "";
            fuliaostr = "";
            COMMAND.CommandBean.formflag = true;
            this.Close();
        }
        //接收数据并显示
        private void datagridviewadddata()
        {

            fornum = COMMAND.Command.maxvalue(yuancailiaorows, tiaoweiliaorows, fuliaorows);
            this.cailiaochoose.Rows.Clear();
            this.cailiaochoose.Rows.Add(fornum);

            for (int j = 0; j < fornum; j++)
            {
                if (j < yuancailiaorows)
                {
                    if (COMMAND.CommandBean.yuancailiaochoose.IndexOf(yuancailiaoSelectresult[j, 1].ToString().Trim()) != -1)
                    {
                        this.cailiaochoose.Rows[j].Cells[0].Value = true;
                    }
                    else
                    {
                        this.cailiaochoose.Rows[j].Cells[0].Value = false;
                    }
                    this.cailiaochoose.Rows[j].Cells[1].Value = yuancailiaoSelectresult[j, 1];
                }
                else
                {
                    this.cailiaochoose.Rows[j].Cells[1].Value = "";
                    //this.cailiaochoose.Rows[j].Cells[0].ReadOnly = true;
                }
                if (j < tiaoweiliaorows)
                {
                    if (COMMAND.CommandBean.tiaoweiliaochoose.IndexOf(tiaoweiliaoSelectresult[j, 1].ToString().Trim()) != -1)
                    {
                        this.cailiaochoose.Rows[j].Cells[2].Value = true;
                    }
                    else
                    {
                        this.cailiaochoose.Rows[j].Cells[2].Value = false;
                    }
                    this.cailiaochoose.Rows[j].Cells[3].Value = tiaoweiliaoSelectresult[j, 1];
                }
                else
                {
                    this.cailiaochoose.Rows[j].Cells[3].Value = "";
                    this.cailiaochoose.Rows[j].Cells[2].ReadOnly = true;
                }
                if (j < fuliaorows)
                {
                    if (COMMAND.CommandBean.fuliaochoose.IndexOf(fuliaoSelectresult[j, 1].ToString().Trim()) != -1)
                    {
                        this.cailiaochoose.Rows[j].Cells[4].Value = true;
                    }
                    else
                    {
                        this.cailiaochoose.Rows[j].Cells[4].Value = false;
                    }
                    this.cailiaochoose.Rows[j].Cells[5].Value = fuliaoSelectresult[j, 1];
                }
                else
                {
                    this.cailiaochoose.Rows[j].Cells[5].Value = "";
                    this.cailiaochoose.Rows[j].Cells[4].ReadOnly = true;
                }
            }

        }

        private void bt_cannal_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
